/**
 * Created by dmrj on 2016/5/3.
 */
define(['jquery', 'model/global', 'appMessageBox', 'appConst'], function ($, global, msgBox, appConst) {
    return {
        searchProject: function (params, callback, errCallBack) {
            var pm = {};
            $.ajax({
                url: 'project/findAll',
                type: 'POST',
                dataType: 'JSON',
                "data": params,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        getHasPerAllProjects: function (callback, errCallBack) {
            $.ajax({
                url: 'project/hasPermissionList',
                type: 'POST',
                dataType: 'JSON',
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        searchCPData: function (url, callback, errCallBack) {

        },
        searchStation: function (params, callback, errCallBack) {
            $.ajax({
                url: 'analysis/stations',
                type: 'POST',
                dataType: 'JSON',
                "data": params,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        searchDistinctSN: function (params, callback, errCallBack) {
            $.ajax({
                url: 'analysis/distinctSN',
                type: 'POST',
                dataType: 'JSON',
                "data": params,
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        },
        getRunChartWarningRule: function (projectId, callback, errCallBack) {
            $.ajax({
                url: "project/ccw",
                type: 'POST',
                data: {"id": projectId},
                success: function (data) {
                    if (data.code == 0) {
                        msgBox.errorBox(data.message);
                        if (typeof errCallBack == 'function') {
                            errCallBack();
                        }
                    } else {
                        if (typeof callback == 'function') {
                            callback(data.body);
                        }
                    }
                },
                error: function (e) {
                    if (e.status == 401) {
                        msgBox.sessionFailureBox();
                    }
                    if (e.status == 500) {
                        msgBox.serverFailureBox();
                    }
                    if (e.status == 404) {
                        msgBox.pathFailureBox();
                    }
                    if (typeof errCallBack == 'function') {
                        errCallBack();
                    }
                }
            });
        }
    };
});